#include <iostream>

namespace Y190606_MSSS {
int main();

int MaxSubseqSum(int A[], int N, int& a, int& b)
{
	int thisSum, maxSum;
	int a0;
	int i;
	a = b = -1;
	a0 = thisSum = maxSum = 0;
	for (i = 0; i < N; ++i) {
		thisSum += A[i];
		if (thisSum > maxSum || (maxSum == 0 && thisSum >= maxSum)) {
			maxSum = thisSum;
			b = i;
			a = a0;
		}
		else if (thisSum < 0) {
			thisSum = 0;
			a0 = i + 1;
		}
	}
	return maxSum;
}

int main() {
	int N;
	int* A;
	int a, b;
	std::cin >> N;
	A = new int[N];
	for (int i = 0; i < N; ++i)
		std::cin >> A[i];
	int c = MaxSubseqSum(A, N, a, b);
	if (a >= 0)
		std::cout << c << " " << A[a] << " " << A[b] << std::endl;
	else
		std::cout << c << " " << A[0] << " " << A[N-1] << std::endl;
	delete []A;
	return 0;
}

}

int main_Y190606_MSSS() {
	return Y190606_MSSS::main();
}